package com.nbst.service.base.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nbst.comnutil.StringUtil;
import com.nbst.dao.mapper.mes.MenuMapper;
import com.nbst.model.base.Menu;
import com.nbst.model.base.User;
import com.nbst.service.base.IBgtMenuService;

/**
 * @ClassName: BgtMenuServiceImpl
 * @Description:报工台权限
 * @author King
 * @date 2019年12月23日
 * 
 */
@Service
public class BgtMenuServiceImpl implements IBgtMenuService {

	@Autowired
	MenuMapper menuMapper;

	@Override
	public String getBgtMenu(String type) {
		User user = (User) SecurityUtils.getSubject().getPrincipal();
		if(user.getfSupplierId()!=null&&user.getfSupplierId()!=0) {
			type = "supplier";
		}
		if(user.getfCustomerId()!=null&&user.getfCustomerId()!=0) {
			type = "customer";
		}
		StringBuffer html = new StringBuffer();
		if(StringUtil.isEmpty(type)) {
			Map<String,Object> map = new HashMap<>(8);
			map.put("bgt", 1);
			if (user != null) {
				if (!user.getAccount().equals("admin") && !user.getAccount().equals("system")) {
					map.put("userid", user.getId());
				}
			}
			List<Menu> list = menuMapper.findByCondition(map);
			if (list.size() == 0 || user == null) {
				html.append("<a href=\"\" onClick=\"signOut()\" ><li>\r\n"
						+ "               	<i class=\"fa fa-sign-out\"></i>\r\n"
						+ "                <span>暂无权限，请退出重新登录</span>\r\n" + "            </li></a>");
			} else {
				for (Menu menu : list) {
					html.append("<a href=\"" + menu.getpUrl() + "\"><li>\r\n" + "               	<i class=\"fa "
							+ menu.getBtIcon() + "\"></i>\r\n" + "                <span>" + menu.getpName() + "</span>\r\n"
							+ "            </li></a>");
					
				}
			}
		}else {
			if("customer".equals(type)) {
				//客户
				html.append("<a href=\"" + "CUOD" + "\"><li>\r\n" + "               	<i class=\"fa "
						/*+ menu.getBtIcon()*/ + "\"></i>\r\n" + "                <span>" + "进度查询" + "</span>\r\n"
						+ "            </li></a>");
				html.append("<a href=\"" + "CMOPA" + "\"><li>\r\n" + "               	<i class=\"fa "
						 + "\"></i>\r\n" + "                <span>" + "修改密码" + "</span>\r\n"
						+ "            </li></a>");
			}else {
				//供应商
				//客户
				html.append("<a href=\"" + "MYOD" + "\"><li>\r\n" + "               	<i class=\"fa "
						/*+ menu.getBtIcon()*/ + "\"></i>\r\n" + "                <span>" + "我的订单" + "</span>\r\n"
						+ "            </li></a>");
				html.append("<a href=\"" + "ORDERSL" + "\"><li>\r\n" + "               	<i class=\"fa "
						/*+ menu.getBtIcon()*/ + "\"></i>\r\n" + "                <span>" + "订单结算清单" + "</span>\r\n"
						+ "            </li></a>");
				html.append("<a href=\"" + "MYOO" + "\"><li>\r\n" + "               	<i class=\"fa "
						/*+ menu.getBtIcon()*/ + "\"></i>\r\n" + "                <span>" + "我的委外单" + "</span>\r\n"
						+ "            </li></a>");
				html.append("<a href=\"" + "OUTSL" + "\"><li>\r\n" + "               	<i class=\"fa "
						/*+ menu.getBtIcon()*/ + "\"></i>\r\n" + "                <span>" + "委外结算清单" + "</span>\r\n"
						+ "            </li></a>");
				html.append("<a href=\"" + "CMOPA" + "\"><li>\r\n" + "               	<i class=\"fa "
						 + "\"></i>\r\n" + "                <span>" + "修改密码" + "</span>\r\n"
						+ "            </li></a>");
			}
			
			
			
			
			
		}
		html.append("<a href=\"\" onClick=\"signOut()\"  ><li>\r\n"
				+ "               	<i class=\"fa fa-sign-out\"></i>\r\n" + "                <span>退出登录</span>\r\n"
				+ "            </li></a>");

		return html.toString();
	}

}
